package demo;

import java.util.concurrent.*;

public class UseCallable {

    static long fib(int n){
        if(n<=1){
            return 1;
        }
        return fib(n-1)+fib(n-2);
    }

    static class FibCallable implements Callable<Long> {
        private final int n;
        FibCallable(int n){
            this.n=n;
        }
        @Override
        public Long call() throws Exception {

            return fib(n);
        }
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {

        ExecutorService pool= Executors.newFixedThreadPool(10);
        FibCallable task=new FibCallable(45);
        Future<Long> future=pool.submit(task);
        TimeUnit.SECONDS.sleep(1);
        System.out.println(future.isDone());
        System.out.println(future.get());
        pool.shutdown();

    }


}
